https://leetcode.cn/problems/nearest-exit-from-entrance-in-maze/
class Solution {
public:
    typedef pair<int ,int> PII;
    int dx[4]={0,0,1,-1};
    int  dy[4]={1,-1,0,0};

public:

    int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {
        int m=maze.size(),n=maze[0].size();
        bool visit[m][n];
        memset(visit,0,sizeof(visit));
        queue<PII> q;
        q.push({entrance[0],entrance[1]});
        visit[entrance[0]][entrance[1]]=true;
        int step=0;
        while(!q.empty())
        {
            step++;
            int sz=q.size();
            for(int i=0;i<sz;i++)
            {
                auto [a,b]=q.front();
                q.pop();
                for(int j=0;j<4;j++)
                {
                    int x=dx[j]+a,y=dy[j]+b;
                    if(x>=0&&x<m &&y>=0&&y<n &&( maze[x][y]!='+')&&!visit[x][y] )
                    {
                        q.push({x,y});
                        visit[x][y]=true;
                        if(x==0 ||x==m-1 ||y==0||y==n-1)
                            return step;
                    }
                }
            }
        }
        return -1;
    }
};